package com.dgut.smart_house.mapper;

import com.dgut.smart_house.domain.Handle;
import com.dgut.smart_house.vo.HandleVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface HandleMapper {

    @Select("select * from handle where deviceId =#{devId} and state=0")
    public Handle findHandleBydeviceIdIfStateIsZero(int devId);

    @Insert("insert into handle (fromUser,deviceId,nodeId,typeId) values(#{fromUser},#{deviceId},#{nodeId},#{typeId})")
    public void generateHandle(Handle handle);

    @Update("update handle set checkTime=current_timestamp(),state=1 where handle_id =#{handleId}")
    public void checkHandle(int handleId);

    public List<HandleVo> listUnHandled(int fromUser);

    public List<HandleVo> listAllHandled(int fromUser);

    public List<HandleVo> listHandled(int fromUser);

    @Select("select * from handle where handle_id = #{handleId}")
    public Handle findHandleById(int handleId);
}
